const express = require('express');
const app = express();
const path = require('path');
const cors = require('cors');
const bodyParser = require('body-parser');
const session = require('express-session')

app.use(session({
  secret: 'test',
  name: 'name',
  cookie: {
    maxAge: 60000
  },
  resave: false,
  saveUninitialized: true,
}));

// 使用 cors 中间件
app.use(cors());

// 使用 body-parser 中间件解析 URL-encoded 数据
app.use(bodyParser.urlencoded({ extended: false }));

// 提供静态文件服务
// http://127.0.0.1:4000/static/carousel/wheel1.jpg
app.use('/static', express.static(path.resolve(__dirname, 'public')));

// 主页路由
// http://127.0.0.1:4000/
app.get('/', (req, res) => {  
    res.send('http://127.0.0.1:4000 创建成功!');
});

// 分发路由
// app.use('/api/exam', require('./router/exam')); 
app.use('/api/ver', require('./router/vrecode')); 
app.use('/api/user', require('./router/user'))
app.use('/api/photo',require('./router/photo'))
app.use('/api/search',require('./router/search'))

const PORT = 4000; 
app.listen(PORT, () => {
    console.log('服务启动了');
    console.log("http://127.0.0.1:" + PORT);
});